public class Main {
    public static void main(String[] args) {
        MyBlockingQueue<Integer> myBlockingQueue = new MyBlockingQueue<>();


        new Thread(()->{
            int i=0;
            while (!Thread.currentThread().isInterrupted()){
                try {
                    myBlockingQueue.put(i++);
                } catch (InterruptedException e) {
                    // 捕获异常时，停止线程的执行
                    Thread.currentThread().interrupt();
                }
            }
        }).start();

        while (!Thread.currentThread().isInterrupted()){
            try {
                Integer i = myBlockingQueue.get();
                System.out.println(i);
                Thread.sleep(500);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}